package data_structure;

public class leetcode_0235 {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if(root.val<=((p.val>q.val)?p.val:q.val)&&root.val>=((p.val<q.val)?p.val:q.val)){
            return root;
        }
        if(root.val>((p.val>q.val)?p.val:q.val)){
            return lowestCommonAncestor(root.left,p,q);
        }
        else{
            return lowestCommonAncestor(root.right,p,q);
        }
    }
}
